<template>
	<view class="content" id="listArea">
		<view v-if='list.length === 0' class="none_data">
			<u-empty text="暂无收藏" mode="favor"></u-empty>
		</view>
		<view v--if="list.length > 0">
			<view class="collect_box" v-for="(item, index) in list" :key="index" @click="openWearPlan(item)">
				<view class="top_box">
					<view class="left_area">
						<view class="flex_row">
							<u-avatar :src="item.user.headphoto" mode="circle" size="85" img-mode="aspectFit"></u-avatar>
							<view class="name">{{ item.user.nickname }}</view>
						</view>
						<view class="title">
							擅长风格
						</view>
					</view>
					<view class="evaluate_area">
						<view v-if="item.user.comprehensiveScore === null" style="30upx;color: #666666;font-weight: bold;">
							暂无评分
						</view>
						<view v-else>
							<view style="font-size: 30upx;color: #666666;font-weight: bold;">评分</view>
							<view class="rateValue">{{ item.user.comprehensiveScore | comprehensiveScore }}</view>
							<u-rate :count="5" :current="item.user.comprehensiveScore | comprehensiveScore" active-color="#FFCC0B" size="29" gutter="5" disabled/>
						</view>
					</view>
				</view>
				<!-- 风格类型 -->
				<view class="list flex_wrap" v-if="item.user.tags !== null">
					<u-tag type="info" shape="circle " mode="plain" v-for="(row, i) in JSON.parse(item.user.tags)" :text="row" :key="i" style="margin-right: 12upx;margin-bottom: 10upx;" />
				</view>
				<view class="list" v-else>
					<view style="font-size: 26upx;color: #666666;padding-top: 4upx;">暂无风格</view>
				</view>
			</view>
			<u-loadmore :status="status" @loadmore="getMoreData"/>
		</view>
		<!-- loading -->
		<view v-if="list === null"></view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				value: '',
				list: null,
				status: 'loadmore',
				pageNum: 1,
				pageSize: 10,
				test: 4.7
			}
		},
		filters: {
			comprehensiveScore(val) {
				if(val === null) {
					return 0
				}else {
					return val.toFixed(1)       
				}
			}
		},
		onLoad() {
			this.findCollections()
		},
		onPullDownRefresh() {
			this.pageNum = 1
			this.status = "loadmore"
			this.findCollections()
		},
		onReachBottom() {
			if(this.status === 'loadmore') {
				this.getMoreData()
			}
		},
		methods: {
			// 查询我收藏的搭配师
			findCollections() {
				var data = {
					pageNum: this.pageNum,
					pageSize: this.pageSize
				}
				
				this.$u.api.findCollections(data).then(res => {
					uni.stopPullDownRefresh();
					if (res.code === 200) {
						this.list = res.data.records
					}
				})
			},
			getMoreData() {
				this.status = 'loading';
				this.pageNum++;
				
				var data = {
					pageNum: this.pageNum,
					pageSize: this.pageSize
				}
				
				this.$u.api.findCollections(data).then(res => {
					if (res.code === 200) {
						this.list = this.list.concat(res.data.records)
						if(this.list.length < res.data.total) {
							this.status = 'loadmore'
						}else {
							this.status = 'nomore'
						}
					}
				})
			},
			// 打开收藏的搭配师
			openWearPlan(data) {
				uni.navigateTo({
					url: "/pagesB/pages/my/indexStylist?id=" + data.contentId
				})
			},
		},

	}
</script>

<style lang="scss">
	page {
		position: relative;
		background-color: #F7F8FA;
	}

	.content {
		padding: 32upx 30upx;

		.none_data {
			height: 100vh;
		}
		
		.collect_box {
			margin-bottom: 28upx;
			width: 100%;
			background: white;
			border-radius: 12upx;
			padding: 20upx;
			.top_box {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: flex-start;
				height: 150upx;
				.left_area {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					height: 100%;
					.name {
						font-size: 32upx;
						margin-left: 21upx;
						font-weight: bold;
					}
					.title {
						color: #333333;
						font-weight: bold;
						font-size: 32upx;
						margin-top: 16upx;
					}
				}
				.evaluate_area {
					height: 100%;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					align-items: flex-end;
					.rateValue {
						font-size: 48upx;
						font-weight: bold;
						color: #333333;
					}
				
					.right_area {
						display: flex;
						justify-content: space-between;
						font-size: 20upx;
						font-weight: 400;
						color: #666666;
					}
				}
			}
			
			.list {
				margin-top: 12upx;
				margin-bottom: 4upx;
				.box {
					padding: 8upx 28upx 8upx 28upx;
					border-radius: 24upx;
					border: 1px solid #1C1724;
					margin-right: 24upx;
					margin-bottom: 5upx;
					display: inline-block;
			
					.img {
						width: 100%;
						display: flex;
						justify-content: center;
			
						.icon {
							font-size: 50upx;
							color: #464646;
						}
					}
			
					.text {
						width: 100%;
						display: flex;
						justify-content: center;
						font-size: 28upx;
						color: #3d3d3d;
					}
				}
			}
			
		}
	}
</style>
